package com.example.camerademo;

import android.annotation.SuppressLint;
import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.FrameLayout;
import android.widget.TextView;

import androidx.annotation.Nullable;

/**
 * author: Liulei
 * created on: 2021/3/31 16:57
 * description:
 */
public class FrameLayoutDemoActivity extends Activity {

    private FrameLayout frame;
    private TextView blueText;
    private TextView greenText;
    private TextView redText;
    private Button blue;
    private Button green;
    private Button red;

    private View.OnClickListener listener = new View.OnClickListener() {
        @SuppressLint("NonConstantResourceId")
        @Override
        public void onClick(View v) {
            switch (v.getId()) {
                case R.id.blue:
                    frame.removeView(blueText);
                    frame.addView(blueText);
                    break;
                case R.id.green:
                    frame.removeView(greenText);
                    frame.addView(greenText);
                    break;
                case R.id.red:
                    frame.removeView(redText);
                    frame.addView(redText);
                    break;
                default:
                    break;
            }
        }
    };

    @SuppressLint("WrongViewCast")
    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_frame_layout_demo);

        frame = findViewById(R.id.frame);
        blueText = findViewById(R.id.blueText);
        redText = findViewById(R.id.redText);
        greenText = findViewById(R.id.greenText);
        blue = findViewById(R.id.blue);
        red = findViewById(R.id.red);
        green = findViewById(R.id.green);

        blue.setOnClickListener(listener);
        red.setOnClickListener(listener);
        green.setOnClickListener(listener);
    }
}
